home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ac2vb3 / frmdemom.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-03-01  |  19.3 KB  |  582 lines

  1. VERSION 2.00
  2. Begin Form frmDemoMain 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "JET 2.0 VB3 Demo"
  5.    ClientHeight    =   6390
  6.    ClientLeft      =   1485
  7.    ClientTop       =   1635
  8.    ClientWidth     =   8970
  9.    Height          =   7110
  10.    Icon            =   FRMDEMOM.FRX:0000
  11.    Left            =   1410
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   6390
  14.    ScaleWidth      =   8970
  15.    Top             =   990
  16.    Width           =   9120
  17.    Begin CommandButton cmdExit 
  18.       Caption         =   "E&xit"
  19.       Height          =   375
  20.       Left            =   1980
  21.       TabIndex        =   11
  22.       Top             =   3420
  23.       Width           =   1035
  24.    End
  25.    Begin CommandButton cmdGo 
  26.       Caption         =   "&Go"
  27.       Height          =   375
  28.       Left            =   720
  29.       TabIndex        =   10
  30.       Top             =   3420
  31.       Width           =   1095
  32.    End
  33.    Begin TextBox txtDBLocation 
  34.       Height          =   315
  35.       Left            =   3780
  36.       TabIndex        =   12
  37.       Text            =   "C:\VB\BIBLIO.MDB"
  38.       Top             =   3480
  39.       Width           =   5055
  40.    End
  41.    Begin SSFrame Frame3D1 
  42.       Caption         =   "&Demo"
  43.       Height          =   3255
  44.       Left            =   120
  45.       TabIndex        =   14
  46.       Top             =   120
  47.       Width           =   3495
  48.       Begin SSOption o3dDemo 
  49.          Caption         =   "Other New Features"
  50.          Height          =   195
  51.          Index           =   20
  52.          Left            =   180
  53.          TabIndex        =   9
  54.          Top             =   2820
  55.          Width           =   2715
  56.       End
  57.       Begin SSOption o3dDemo 
  58.          Caption         =   "Correlated Subqueries"
  59.          Height          =   195
  60.          Index           =   3
  61.          Left            =   180
  62.          TabIndex        =   3
  63.          Top             =   1080
  64.          Width           =   2715
  65.       End
  66.       Begin SSOption o3dDemo 
  67.          Caption         =   "Top n Query"
  68.          Height          =   195
  69.          Index           =   2
  70.          Left            =   180
  71.          TabIndex        =   2
  72.          Top             =   840
  73.          Width           =   2715
  74.       End
  75.       Begin SSOption o3dDemo 
  76.          Caption         =   "DDL Create Index"
  77.          Height          =   195
  78.          Index           =   12
  79.          Left            =   180
  80.          TabIndex        =   6
  81.          Top             =   1980
  82.          Width           =   2895
  83.       End
  84.       Begin SSOption o3dDemo 
  85.          Caption         =   "Insert using Values clause"
  86.          Height          =   195
  87.          Index           =   14
  88.          Left            =   180
  89.          TabIndex        =   8
  90.          Top             =   2460
  91.          Width           =   2715
  92.       End
  93.       Begin SSOption o3dDemo 
  94.          Caption         =   "DDL Drop Table"
  95.          Height          =   195
  96.          Index           =   13
  97.          Left            =   180
  98.          TabIndex        =   7
  99.          Top             =   2220
  100.          Width           =   2715
  101.       End
  102.       Begin SSOption o3dDemo 
  103.          Caption         =   "DDL Alter Table - add column"
  104.          Height          =   195
  105.          Index           =   11
  106.          Left            =   180
  107.          TabIndex        =   5
  108.          Top             =   1740
  109.          Width           =   2895
  110.       End
  111.       Begin SSOption o3dDemo 
  112.          Caption         =   "DDL Create Table"
  113.          Height          =   195
  114.          Index           =   10
  115.          Left            =   180
  116.          TabIndex        =   4
  117.          Top             =   1500
  118.          Width           =   2715
  119.       End
  120.       Begin SSOption o3dDemo 
  121.          Caption         =   "Sub-Select Query"
  122.          Height          =   195
  123.          Index           =   1
  124.          Left            =   180
  125.          TabIndex        =   1
  126.          Top             =   600
  127.          Width           =   2715
  128.       End
  129.       Begin SSOption o3dDemo 
  130.          Caption         =   "UNION Query"
  131.          Height          =   195
  132.          Index           =   0
  133.          Left            =   180
  134.          TabIndex        =   0
  135.          Top             =   360
  136.          Width           =   2715
  137.       End
  138.    End
  139.    Begin Grid grdDemo 
  140.       Cols            =   10
  141.       FixedCols       =   0
  142.       Height          =   2415
  143.       Left            =   120
  144.       Rows            =   10
  145.       TabIndex        =   13
  146.       Top             =   3840
  147.       Width           =   8715
  148.    End
  149.    Begin Label Label2 
  150.       BackStyle       =   0  'Transparent
  151.       Caption         =   "SQL Command"
  152.       Height          =   255
  153.       Left            =   3900
  154.       TabIndex        =   17
  155.       Top             =   120
  156.       Width           =   1935
  157.    End
  158.    Begin Label lblExampleText 
  159.       BorderStyle     =   1  'Fixed Single
  160.       FontBold        =   0   'False
  161.       FontItalic      =   0   'False
  162.       FontName        =   "MS Sans Serif"
  163.       FontSize        =   9.75
  164.       FontStrikethru  =   0   'False
  165.       FontUnderline   =   0   'False
  166.       Height          =   2775
  167.       Left            =   3780
  168.       TabIndex        =   16
  169.       Top             =   300
  170.       Width           =   4935
  171.    End
  172.    Begin Label Label1 
  173.       BackStyle       =   0  'Transparent
  174.       Caption         =   "Sample DB Location"
  175.       Height          =   255
  176.       Left            =   3780
  177.       TabIndex        =   15
  178.       Top             =   3240
  179.       Width           =   2175
  180.    End
  181.    Begin Shape Shape1 
  182.       BackColor       =   &H00808080&
  183.       BackStyle       =   1  'Opaque
  184.       BorderStyle     =   0  'Transparent
  185.       Height          =   2775
  186.       Left            =   3840
  187.       Top             =   360
  188.       Width           =   4935
  189.    End
  190.    Begin Menu mnuFile 
  191.       Caption         =   "F&ile"
  192.       Begin Menu mnuFileCommands 
  193.          Caption         =   "&About"
  194.          Index           =   0
  195.       End
  196.       Begin Menu mnuFileCommands 
  197.          Caption         =   "E&xit"
  198.          Index           =   1
  199.       End
  200.    End
  201. Option Explicit
  202. Dim gDefaultDatabase As database
  203. Dim DBOpen_OK As Integer
  204. Sub ClearGrid ()
  205.     Dim i As Integer
  206.     Dim j As Integer
  207.     For i = 0 To 9
  208.         For j = 0 To 9
  209.             grdDemo.Col = i
  210.             grdDemo.Row = j
  211.             grdDemo.Text = ""
  212.         Next j
  213.     Next i
  214. End Sub
  215. Sub cmdExit_Click ()
  216.     Unload Me
  217. End Sub
  218. Sub cmdGo_Click ()
  219.     On Error Resume Next
  220.     Dim ds As dynaset
  221.     Dim i As Integer
  222.     If Not DBOpen_OK Then
  223.         Set gDefaultDatabase = OpenDatabase(txtDBLocation.Text)
  224.         If Err <> 0 Then
  225.             MsgBox "Error Opening: " & txtDBLocation.Text
  226.             Exit Sub
  227.         End If
  228.         DBOpen_OK = True
  229.     End If
  230.     ClearGrid
  231.     ResetGridWidths
  232.     'UNION Query
  233.     If o3dDemo(0).Value = -1 Then
  234.         Me.MousePointer = 11
  235.         grdDemo.ColWidth(1) = 2000
  236.         grdDemo.ColWidth(2) = 1500
  237.         grdDemo.Row = 0
  238.         grdDemo.Col = 0
  239.         grdDemo.Text = "ID"
  240.         grdDemo.Col = 1
  241.         grdDemo.Text = "Name"
  242.         grdDemo.Col = 2
  243.         grdDemo.Text = "Type"
  244.         Set ds = gDefaultDatabase.CreateDynaset(lblExampleText)
  245.         If ds.RecordCount <> 0 Then
  246.             i = 1
  247.             Do Until ds.EOF
  248.                 grdDemo.Row = (i)
  249.                 grdDemo.Col = 0
  250.                 grdDemo.Text = ds(0)
  251.                 grdDemo.Col = 1
  252.                 grdDemo.Text = ds(1)
  253.                 grdDemo.Col = 2
  254.                 grdDemo.Text = ds(2)
  255.                 
  256.                 ds.MoveNext
  257.                 i = i + 1
  258.                 If i > 9 Then
  259.                     Exit Do
  260.                 End If
  261.             Loop
  262.         End If
  263.         Me.MousePointer = 0
  264.     End If
  265.     'Sub-Select Query
  266.     If o3dDemo(1).Value = -1 Then
  267.         Me.MousePointer = 11
  268.         
  269.         grdDemo.ColWidth(1) = 2000
  270.         grdDemo.ColWidth(2) = 2500
  271.         grdDemo.Row = 0
  272.         grdDemo.Col = 0
  273.         grdDemo.Text = "Pub ID"
  274.         grdDemo.Col = 1
  275.         grdDemo.Text = "Name"
  276.         grdDemo.Col = 2
  277.         grdDemo.Text = "Company Name"
  278.         Set ds = gDefaultDatabase.CreateDynaset(lblExampleText)
  279.         If ds.RecordCount <> 0 Then
  280.             i = 1
  281.             Do Until ds.EOF
  282.                 grdDemo.Row = (i)
  283.                 grdDemo.Col = 0
  284.                 grdDemo.Text = ds("PubID")
  285.                 grdDemo.Col = 1
  286.                 grdDemo.Text = ds("Name")
  287.                 grdDemo.Col = 2
  288.                 grdDemo.Text = ds("Company Name")
  289.                 
  290.                 ds.MoveNext
  291.                 i = i + 1
  292.                 If i > 9 Then
  293.                     Exit Do
  294.                 End If
  295.             Loop
  296.         End If
  297.         
  298.         Me.MousePointer = 0
  299.     End If
  300.     'Top n query
  301.     If o3dDemo(2).Value = -1 Then
  302.         Me.MousePointer = 11
  303.         
  304.         grdDemo.ColWidth(0) = 1400
  305.         grdDemo.ColWidth(1) = 2000
  306.         grdDemo.ColWidth(2) = 2000
  307.         grdDemo.ColWidth(3) = 4000
  308.         grdDemo.Row = 0
  309.         grdDemo.Col = 0
  310.         grdDemo.Text = "Year Published"
  311.         grdDemo.Col = 1
  312.         grdDemo.Text = "Author"
  313.         grdDemo.Col = 2
  314.         grdDemo.Text = "Name"
  315.         grdDemo.Col = 3
  316.         grdDemo.Text = "Title"
  317.         Set ds = gDefaultDatabase.CreateDynaset(lblExampleText)
  318.         If ds.RecordCount <> 0 Then
  319.             i = 1
  320.             Do Until ds.EOF
  321.                 grdDemo.Row = (i)
  322.                 grdDemo.Col = 0
  323.                 grdDemo.Text = ds("Year Published")
  324.                 grdDemo.Col = 1
  325.                 grdDemo.Text = ds("Author")
  326.                 grdDemo.Col = 2
  327.                 grdDemo.Text = ds("Name")
  328.                 grdDemo.Col = 3
  329.                 grdDemo.Text = ds("Title")
  330.                 
  331.                 ds.MoveNext
  332.                 i = i + 1
  333.                 If i > 9 Then
  334.                     Exit Do
  335.                 End If
  336.             Loop
  337.         End If
  338.         Me.MousePointer = 0
  339.     End If
  340.     'Corellated sub-query
  341.     If o3dDemo(3).Value = -1 Then
  342.         
  343.         Me.MousePointer = 11
  344.         grdDemo.ColWidth(0) = 800
  345.         grdDemo.ColWidth(1) = 1800
  346.         grdDemo.ColWidth(2) = 3500
  347.         
  348.         grdDemo.Row = 0
  349.         grdDemo.Col = 0
  350.         grdDemo.Text = "Pub ID"
  351.         grdDemo.Col = 1
  352.         grdDemo.Text = "Author"
  353.         grdDemo.Col = 2
  354.         grdDemo.Text = "Title"
  355.         Set ds = gDefaultDatabase.CreateDynaset(lblExampleText)
  356.         If ds.RecordCount <> 0 Then
  357.             i = 1
  358.             Do Until ds.EOF
  359.                 grdDemo.Row = (i)
  360.                 grdDemo.Col = 0
  361.                 grdDemo.Text = ds("PubID")
  362.                 grdDemo.Col = 1
  363.                 grdDemo.Text = ds("Author")
  364.                 grdDemo.Col = 2
  365.                 grdDemo.Text = ds("Title")
  366.                 
  367.                 ds.MoveNext
  368.                 i = i + 1
  369.                 If i > 9 Then
  370.                     Exit Do
  371.                 End If
  372.             Loop
  373.         End If
  374.         
  375.         Me.MousePointer = 0
  376.     End If
  377.     'Create Table
  378.     If o3dDemo(10).Value = -1 Then
  379.         If TableExists("My Test Table") Then
  380.             MsgBox "Table [My Test Table] already exists. Try doing a DROP TABLE command"
  381.             Exit Sub
  382.         End If
  383.         
  384.         On Error Resume Next
  385.         gDefaultDatabase.Execute lblExampleText
  386.         If Err <> 0 Then
  387.             MsgBox "error creating Test Table"
  388.         End If
  389.         
  390.         On Error GoTo 0
  391.     End If
  392.     'Add column
  393.     If o3dDemo(11).Value = -1 Then
  394.         If Not TableExists("My Test Table") Then
  395.             MsgBox "Table [My Test Table] does not exist. Try doing a CREATE TABLE command"
  396.             Exit Sub
  397.         End If
  398.         
  399.         On Error Resume Next
  400.         
  401.         gDefaultDatabase.Execute lblExampleText
  402.         If Err <> 0 Then
  403.             MsgBox "Error adding column to My Test Table."
  404.         End If
  405.         
  406.         On Error GoTo 0
  407.     End If
  408.     'Create Index
  409.     If o3dDemo(12).Value = -1 Then
  410.         If Not TableExists("My Test Table") Then
  411.             MsgBox "Table [My Test Table] does not exist. Try doing a CREATE TABLE command"
  412.             Exit Sub
  413.         End If
  414.         
  415.         On Error Resume Next
  416.         
  417.         gDefaultDatabase.Execute lblExampleText
  418.         If Err <> 0 Then
  419.             MsgBox "Error creating PrimaryKey index on My Test Table."
  420.         End If
  421.         
  422.         On Error GoTo 0
  423.     End If
  424.     'Drop Table
  425.     If o3dDemo(13).Value = -1 Then
  426.         If Not TableExists("My Test Table") Then
  427.             MsgBox "Table [My Test Table] does not exist. Try doing a CREATE TABLE command"
  428.             Exit Sub
  429.         End If
  430.         
  431.         On Error Resume Next
  432.         
  433.         gDefaultDatabase.Execute lblExampleText
  434.         If Err <> 0 Then
  435.             MsgBox "Error dropping table My Test Table."
  436.         End If
  437.         
  438.         On Error GoTo 0
  439.     End If
  440.     'Insert Values...
  441.     If o3dDemo(14).Value = -1 Then
  442.         If Not TableExists("My Test Table") Then
  443.             MsgBox "Table [My Test Table] does not exist. Try doing a CREATE TABLE command"
  444.             Exit Sub
  445.         End If
  446.         
  447.         On Error Resume Next
  448.         
  449.         gDefaultDatabase.Execute lblExampleText
  450.         If Err <> 0 Then
  451.             MsgBox "Error inserting values into My Test Table."
  452.         End If
  453.         
  454.         On Error GoTo 0
  455.     End If
  456. End Sub
  457. Sub Form_Load ()
  458.     Dim i As Integer
  459.     Me.Top = (screen.Height - Me.Height) / 2
  460.     Me.Left = (screen.Width - Me.Width) / 2
  461.     ResetGridWidths
  462.     o3dDemo(0).Value = 1
  463. End Sub
  464. Sub Form_Unload (Cancel As Integer)
  465.     If DBOpen_OK Then
  466.         gDefaultDatabase.Close
  467.     End If
  468.     End
  469. End Sub
  470. Sub mnuFileCommands_Click (index As Integer)
  471.     Select Case index
  472.         
  473.         Case 0: frmAbout.Show 1
  474.         Case 1: Unload Me
  475.     End Select
  476. End Sub
  477. Sub o3dDemo_Click (index As Integer, Value As Integer)
  478.     Dim strNewText As String
  479.     Dim crlf As String
  480.     crlf = Chr$(13) & Chr$(10)
  481.     Select Case index
  482.         Case 0' UNION
  483.             strNewText = "SELECT DISTINCTROW " & crlf
  484.             strNewText = strNewText & "Authors.Au_ID as IDNum , " & crlf
  485.             strNewText = strNewText & "Authors.Author as IDName, " & crlf
  486.             strNewText = strNewText & "'Author' as ColType " & crlf
  487.             strNewText = strNewText & "FROM Authors " & crlf
  488.             strNewText = strNewText & "UNION SELECT DISTINCTROW " & crlf
  489.             strNewText = strNewText & "Publishers.PubID, " & crlf
  490.             strNewText = strNewText & "Publishers.Name, " & crlf
  491.             strNewText = strNewText & "'Publisher' as ColType " & crlf
  492.             strNewText = strNewText & "FROM Publishers " & crlf
  493.             strNewText = strNewText & "ORDER BY IDName; "
  494.             
  495.         Case 1' Sub-Select Query
  496.             strNewText = "SELECT DISTINCTROW Publishers.* " & crlf
  497.             strNewText = strNewText & "FROM Publishers " & crlf
  498.             strNewText = strNewText & "where Publishers.PubID in " & crlf
  499.             strNewText = strNewText & "(SELECT DISTINCT Titles.PubID " & crlf
  500.             strNewText = strNewText & "FROM Titles " & crlf
  501.             strNewText = strNewText & "WHERE ((Titles.Title Like '*SQL*'))) " & crlf
  502.             strNewText = strNewText & "ORDER BY [Company Name]; "
  503.             
  504.         Case 2' Top n Query
  505.             strNewText = "SELECT DISTINCTROW TOP 5 " & crlf
  506.             strNewText = strNewText & "Titles.[Year Published], " & crlf
  507.             strNewText = strNewText & "Authors.Author, " & crlf
  508.             strNewText = strNewText & "Publishers.Name, " & crlf
  509.             strNewText = strNewText & "Titles.Title " & crlf
  510.             strNewText = strNewText & "FROM (Titles INNER JOIN Authors ON Titles.Au_ID = Authors.Au_ID) " & crlf
  511.             strNewText = strNewText & "INNER JOIN Publishers ON Titles.PubID = Publishers.PubID " & crlf
  512.             strNewText = strNewText & "ORDER BY Titles.[Year Published], Authors.Author; "
  513.         
  514.         Case 3' Corellated subqueries:
  515.             strNewText = "SELECT DISTINCTROW " & crlf
  516.             strNewText = strNewText & "A.PubID, Authors.Author, A.Title " & crlf
  517.             strNewText = strNewText & "FROM Titles as A " & crlf
  518.             strNewText = strNewText & "INNER JOIN Authors ON A.Au_ID = Authors.Au_ID " & crlf
  519.             strNewText = strNewText & "WHERE " & crlf
  520.             strNewText = strNewText & "(1 < (SELECT count(*) from Titles as B " & crlf
  521.             strNewText = strNewText & "where A.PubID = B.PubID)) " & crlf
  522.             strNewText = strNewText & "ORDER BY A.PubID, Authors.Author; "
  523.             
  524.         Case 10' DDL Create Table
  525.             strNewText = "CREATE TABLE [My Test Table] " & crlf
  526.             strNewText = strNewText & "([Last Name] text (20), " & crlf
  527.             strNewText = strNewText & "[First Name] text (20), " & crlf
  528.             strNewText = strNewText & "[Department] text (2), " & crlf
  529.             strNewText = strNewText & "[Date Added] DateTime) "
  530.         Case 11 'DDL Alter Table - add column
  531.             strNewText = strNewText & "ALTER TABLE [My Test Table] " & crlf
  532.             strNewText = strNewText & "ADD COLUMN RecID COUNTER; "
  533.         Case 12' DDL Create Index
  534.             strNewText = strNewText & "CREATE  INDEX 'PrimaryKey' " & crlf
  535.             strNewText = strNewText & "ON  [My Test Table] " & crlf
  536.             strNewText = strNewText & "(RecID) WITH PRIMARY; "
  537.         Case 13' DDL Drop Table
  538.             strNewText = "DROP TABLE [My Test Table]"
  539.         
  540.         Case 14' Insert values...
  541.             strNewText = "INSERT INTO [My Test Table] " & crlf
  542.             strNewText = strNewText & "( [Last Name], " & crlf
  543.             strNewText = strNewText & "[First Name], " & crlf
  544.             strNewText = strNewText & "[Department], " & crlf
  545.             strNewText = strNewText & "[Date Added] ) " & crlf
  546.             strNewText = strNewText & "VALUES " & crlf
  547.             strNewText = strNewText & "('Smith', " & crlf
  548.             strNewText = strNewText & "'John', " & crlf
  549.             strNewText = strNewText & "'20', " & crlf
  550.             strNewText = strNewText & "#04/1/94#);"
  551.         
  552.         Case 20' other features
  553.             strNewText = "* Cascading updates and deletes " & crlf
  554.             strNewText = strNewText & "* Update non-joined fields on 'one' side of a join " & crlf
  555.             strNewText = strNewText & "* Fill in the blank rows of a LEFT JOIN " & crlf
  556.             strNewText = strNewText & "* Support for Paradox 4.x format"
  557.     End Select
  558.     lblExampleText = strNewText
  559. End Sub
  560. Sub ResetGridWidths ()
  561.     Dim i As Integer
  562.     For i = 0 To 9
  563.         grdDemo.ColWidth(i) = 835
  564.     Next i
  565. End Sub
  566. Function TableExists (tname As Variant) As Integer
  567.     TableExists = False
  568.     Dim ss As snapshot
  569.     Set ss = gDefaultDatabase.ListTables()
  570.     If ss.RecordCount <> 0 Then
  571.         ss.MoveFirst
  572.         Do Until ss.EOF
  573.             'Debug.Print ss("Name")
  574.             If ss("Name") = tname Then
  575.                 TableExists = True
  576.                 Exit Do
  577.             End If
  578.             ss.MoveNext
  579.         Loop
  580.     End If
  581. End Function
  582.